<template>
	<view class="">
		<u-loading-page :loading="isLoading"></u-loading-page>
		<view class="app" v-show="!isLoading">
			<u-form size="medium" ref="uForm" :model="obj.configuration" labelWidth="200rpx" class="u-p-l-30 u-p-r-20">
				<u-text bold size="32rpx" margin="20rpx 0" text="积分设置"></u-text>
				<u-form-item label="积分文字" prop="integral_text"><u-input v-model="obj.configuration.integral_text"></u-input></u-form-item>
				<u-form-item label="是否开启"><u-switch v-model="obj.configuration.is_open" :activeValue="1" :inactiveValue="0" size="20"></u-switch></u-form-item>
				<u-form-item label="积分上限">
					<u-radio-group v-model="obj.configuration.integral_upper">
						<u-radio customStyle="margin-right:32rpx" :name="0" label="不限制"></u-radio>
						<u-radio :name="1" label="自定义"></u-radio>
					</u-radio-group>
				</u-form-item>
				<u-form-item prop="integral_upper_limit" label="最大上限" v-if="obj.configuration.integral_upper == 1">
					<u-input v-model="obj.configuration.integral_upper_limit"></u-input>
				</u-form-item>
				<u-alert
					v-if="obj.configuration.integral_upper == 1"
					type="primary"
					description="用户积分大于等于此值时将无法继续增加，后台手动充值不限制，已持有积分不限制"
				></u-alert>
				<u-line></u-line>
				<u-text bold size="32rpx" margin="20rpx 0" text="余额设置"></u-text>

				<u-form-item label="余额文字" prop="balance_text"><u-input v-model="obj.configuration.balance_text"></u-input></u-form-item>
				<u-form-item label="充值设置"><u-switch v-model="obj.configuration.balance_setting" :activeValue="1" :inactiveValue="0" size="20"></u-switch></u-form-item>
				<u-form-item label="最低充值金额" prop="balance_cash" v-if="obj.configuration.balance_setting == 1">
					<u-input v-model="obj.configuration.balance_cash"></u-input>
				</u-form-item>
				<u-alert v-if="obj.configuration.balance_setting == 1" type="primary" description="账户充值时，最低允许的充值金额，系统最低可支持0.1元"></u-alert>
				<u-form-item label="余额提现"><u-switch v-model="obj.configuration.withdraw" :activeValue="1" :inactiveValue="0" size="20"></u-switch></u-form-item>

				<u-form-item label="线上提现方式">
					<u-checkbox-group v-model="obj.configuration.withdraw_type">
						<u-checkbox name="1" label="微信钱包"></u-checkbox>
						<!-- <u-checkbox label="2">支付宝</u-checkbox> -->
					</u-checkbox-group>
				</u-form-item>
				<u-form-item label="线下提现方式">
					<u-checkbox-group v-model="obj.configuration.withdraw_type_outline">
						<u-checkbox customStyle="margin-right:32rpx" name="1" label="微信"></u-checkbox>
						<u-checkbox customStyle="margin-right:32rpx" name="2" label="支付宝"></u-checkbox>
						<u-checkbox name="3" label="银行卡"></u-checkbox>
					</u-checkbox-group>
				</u-form-item>
				<u-form-item label="提现限制">
					<u-radio-group v-model="obj.configuration.withdraw_limit">
						<u-radio customStyle="margin-right:32rpx" :name="0" label="不限制"></u-radio>
						<u-radio :name="1" label="自定义"></u-radio>
					</u-radio-group>
				</u-form-item>

				<u-form-item label="提现门槛" prop="withdraw_limit_cash" v-if="obj.configuration.withdraw_limit == 1">
					<u-input v-model="obj.configuration.withdraw_limit_cash"></u-input>
				</u-form-item>
				<u-alert v-if="obj.configuration.withdraw_limit == 1" type="primary" description="用户最低提现金额"></u-alert>

				<u-form-item label="提现手续费">
					<u-radio-group v-model="obj.configuration.withdraw_service">
						<u-radio customStyle="margin-right:32rpx" :name="0" label="不扣除"></u-radio>
						<u-radio :name="1" label="自定义"></u-radio>
					</u-radio-group>
				</u-form-item>
				<block v-if="obj.configuration.withdraw_service == 1">
					<u-form-item label="手续费" prop="service_charge"><u-input v-model="obj.configuration.service_charge"></u-input></u-form-item>
					<u-form-item label="免手续费">
						<u-radio-group v-model="obj.configuration.is_free_fee" style="margin-left:10px;">
							<u-radio customStyle="margin-right:32rpx" :name="0" label="不免手续费"></u-radio>
							<u-radio :name="1" label="自定义区间"></u-radio>
						</u-radio-group>
					</u-form-item>
					<u-form-item label="免手续费区间" v-if="obj.configuration.is_free_fee == 1">
						<u-input v-model="obj.configuration.free_fee_section[0]"></u-input>
						-
						<u-input v-model="obj.configuration.free_fee_section[1]"></u-input>
					</u-form-item>
					<u-alert
						v-if="obj.configuration.is_free_fee == 1"
						type="primary"
						description="当手续费金额在此区间内时，不扣除手续费，结束金额 必须大于 开始金额。例如 设置开始金额0元 结束金额5元，只有手续费金额高于5元时，才扣除"
					></u-alert>
				</block>
				<u-line margin="20rpx 0"></u-line>
				<u-text bold size="32rpx" margin="20rpx 0" text="分销提现设置"></u-text>

				<u-form-item label="分销提现"><u-switch v-model="obj.configuration.agent_withdraw" :activeValue="1" :inactiveValue="0" size="20"></u-switch></u-form-item>
				<u-form-item label="线上提现方式">
					<u-checkbox-group v-model="obj.configuration.agent_withdraw_type">
						<u-checkbox customStyle="margin-right:32rpx" name="1" label="微信钱包"></u-checkbox>
						<u-checkbox name="2" label="余额"></u-checkbox>
					</u-checkbox-group>
				</u-form-item>
				<u-form-item label="线下提现方式">
					<u-checkbox-group v-model="obj.configuration.agent_withdraw_type_outline">
						<u-checkbox customStyle="margin-right:32rpx" name="1" label="微信"></u-checkbox>
						<u-checkbox customStyle="margin-right:32rpx" name="2" label="支付宝"></u-checkbox>
						<u-checkbox name="3" label="银行卡"></u-checkbox>
					</u-checkbox-group>
				</u-form-item>
				<u-form-item label="提现限制">
					<u-radio-group v-model="obj.configuration.agent_withdraw_limit">
						<u-radio customStyle="margin-right:32rpx" :name="0" label="不限制"></u-radio>
						<u-radio :name="1" label="自定义"></u-radio>
					</u-radio-group>
				</u-form-item>
				<u-form-item prop="agent_withdraw_limit_cash" label="提现门槛" v-if="obj.configuration.agent_withdraw_limit == 1">
					<u-input v-model="obj.configuration.agent_withdraw_limit_cash"></u-input>
				</u-form-item>

				<u-form-item label="提现手续费">
					<u-radio-group v-model="obj.configuration.agent_withdraw_service">
						<u-radio customStyle="margin-right:32rpx" :name="0" label="不扣除"></u-radio>
						<u-radio :name="1" label="自定义"></u-radio>
					</u-radio-group>
				</u-form-item>
				<block v-if="obj.configuration.agent_withdraw_service == 1">
					<u-form-item label="手续费" prop="agent_service_charge"><u-input v-model="obj.configuration.agent_service_charge"></u-input></u-form-item>
					<u-form-item label="免手续费">
						<u-radio-group v-model="obj.configuration.agent_is_free_fee" style="margin-left:10px;">
							<u-radio customStyle="margin-right:32rpx" :name="0" label="不免手续费"></u-radio>
							<u-radio :name="1" label="自定义区间"></u-radio>
						</u-radio-group>
					</u-form-item>
					<u-form-item label="免手续费区间" v-if="obj.configuration.agent_is_free_fee == 1">
						<u-input v-model="obj.configuration.agent_free_fee_section[0]"></u-input>
						-
						<u-input v-model="obj.configuration.agent_free_fee_section[1]"></u-input>
					</u-form-item>
					<u-alert
						v-if="obj.configuration.agent_is_free_fee == 1"
						type="primary"
						description="当手续费金额在此区间内时，不扣除手续费，结束金额 必须大于 开始金额。例如 设置开始金额0元 结束金额5元，只有手续费金额高于5元时，才扣除"
					></u-alert>
				</block>
				<u-line margin="20rpx 0"></u-line>
				<u-text bold size="32rpx" margin="20rpx 0" text="商户余额提现"></u-text>

				<u-form-item label="商户余额提现"><u-switch v-model="obj.configuration.merchant_withdraw" :activeValue="1" :inactiveValue="0" size="20"></u-switch></u-form-item>

				<u-form-item label="线上提现方式">
					<u-checkbox-group v-model="obj.configuration.merchant_withdraw_type">
						<u-checkbox customStyle="margin-right:32rpx" name="1" label="微信钱包"></u-checkbox>
						<u-checkbox name="2" label="余额"></u-checkbox>
					</u-checkbox-group>
				</u-form-item>
				<u-form-item label="线下提现方式">
					<u-checkbox-group v-model="obj.configuration.merchant_withdraw_type_outline">
						<u-checkbox customStyle="margin-right:32rpx" name="1" label="微信"></u-checkbox>
						<u-checkbox customStyle="margin-right:32rpx" name="2" label="支付宝"></u-checkbox>
						<u-checkbox name="3" label="银行卡"></u-checkbox>
					</u-checkbox-group>
				</u-form-item>

				<u-form-item label="提现限制">
					<u-radio-group v-model="obj.configuration.merchant_withdraw_limit">
						<u-radio customStyle="margin-right:32rpx" :name="0" label="不限制"></u-radio>
						<u-radio :name="1" label="自定义"></u-radio>
					</u-radio-group>
				</u-form-item>
				<u-form-item label="提现门槛" prop="merchant_withdraw_limit_cash" v-if="obj.configuration.merchant_withdraw_limit == 1">
					<u-input v-model="obj.configuration.merchant_withdraw_limit_cash"></u-input>
				</u-form-item>

				<u-form-item label="提现手续费">
					<u-radio-group v-model="obj.configuration.merchant_withdraw_service">
						<u-radio customStyle="margin-right:32rpx" :name="0" label="不扣除"></u-radio>
						<u-radio :name="1" label="自定义"></u-radio>
					</u-radio-group>
				</u-form-item>
				<block v-if="obj.configuration.merchant_withdraw_service == 1">
					<u-form-item label="手续费" prop="merchant_service_charge"><u-input v-model="obj.configuration.merchant_service_charge"></u-input></u-form-item>
					<u-form-item label="免手续费">
						<u-radio-group v-model="obj.configuration.merchant_is_free_fee" style="margin-left:10px;">
							<u-radio customStyle="margin-right:32rpx" :name="0" label="不免手续费"></u-radio>
							<u-radio :name="1" label="自定义区间"></u-radio>
						</u-radio-group>
					</u-form-item>
					<u-form-item label="免手续费区间" v-if="obj.configuration.merchant_is_free_fee == 1">
						<u-input v-model="obj.configuration.merchant_free_fee_section[0]"></u-input>
						-
						<u-input v-model="obj.configuration.merchant_free_fee_section[1]"></u-input>
					</u-form-item>
					<u-alert
						v-if="obj.configuration.merchant_is_free_fee == 1"
						type="primary"
						description="当手续费金额在此区间内时，不扣除手续费，结束金额 必须大于 开始金额。例如 设置开始金额0元 结束金额5元，只有手续费金额高于5元时，才扣除"
					></u-alert>
				</block>
			</u-form>
			<u-gap height="120rpx"></u-gap>
			<view class="u-flex u-flex-items-center footer">
				<u-button size="small" shape="circle" @click="cancal">取消</u-button>
				<u-button class="u-m-l-60" type="primary" size="small" shape="circle" @click="saveData">确定</u-button>
			</view>
			<u-toast ref="uToast"></u-toast>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			isLoading: false,
			obj: {
				type: 'integralBalance',
				status: 1,
				configuration: {
					integral_text: '',
					integral_upper: 0,
					integral_upper_limit: 0,
					is_open: 0,
					balance_text: '',
					balance_setting: 0,
					balance_cash: 0.1,
					withdraw: 1,
					withdraw_type: [],
					withdraw_type_outline: [],
					withdraw_limit: 1,
					withdraw_limit_cash: '100.00',
					withdraw_service: 0,
					service_charge: 5.5,
					is_free_fee: 0,
					free_fee_section: [0, 0],
					agent_withdraw: 1,
					agent_withdraw_type: [],
					agent_withdraw_type_outline: [],
					agent_withdraw_limit: 0,
					agent_withdraw_limit_cash: '100.00',
					agent_withdraw_service: 0,
					agent_service_charge: 5.5,
					agent_is_free_fee: 0,
					agent_free_fee_section: [0, 0],
					merchant_withdraw: 1,
					merchant_withdraw_type: [],
					merchant_withdraw_type_outline: [],
					merchant_withdraw_limit: 0,
					merchant_withdraw_limit_cash: '100.00',
					merchant_withdraw_service: 0,
					merchant_service_charge: 5.5,
					merchant_is_free_fee: 0,
					merchant_free_fee_section: [0, 0]
				}
			},
			itemRules: {
				integral_text: [
					{
						type: 'string',
						required: true,
						message: '请输入积分文字',
						trigger: ['blur', 'change']
					}
				],
				integral_upper_limit: [
					{
						type: 'string',
						required: true,
						message: '请输入最大上限',
						trigger: ['blur', 'change']
					}
				],
				balance_text: [
					{
						type: 'string',
						required: true,
						message: '请输入余额文字',
						trigger: ['blur', 'change']
					}
				],
				balance_cash: [
					{
						type: 'string',
						required: true,
						message: '请输入最低充值金额',
						trigger: ['blur', 'change']
					}
				],
				withdraw_limit_cash: [
					{
						type: 'string',
						required: true,
						message: '请输入提现门槛',
						trigger: ['blur', 'change']
					}
				],
				service_charge: [
					{
						type: 'string',
						required: true,
						message: '请输入提现手续费',
						trigger: ['blur', 'change']
					}
				],
				agent_withdraw_limit_cash: [
					{
						type: 'string',
						required: true,
						message: '请输入提现门槛',
						trigger: ['blur', 'change']
					}
				],
				agent_service_charge: [
					{
						type: 'string',
						required: true,
						message: '请输入提现手续费',
						trigger: ['blur', 'change']
					}
				],
				merchant_withdraw_limit_cash: [
					{
						type: 'string',
						required: true,
						message: '请输入提现门槛',
						trigger: ['blur', 'change']
					}
				],
				merchant_service_charge: [
					{
						type: 'string',
						required: true,
						message: '请输入提现手续费',
						trigger: ['blur', 'change']
					}
				]
			}
		};
	},
	components: {},
	onLoad() {
		this.getConfig();
	},
	onReady() {
		this.$refs.uForm.setRules(this.itemRules);
	},
	onPullDownRefresh() {
		this.getConfig();
	},
	methods: {
		//获取站点配置数据
		getConfig(type) {
			this.isLoading = true;
			uni.$u.http
				.get('/madmin/configuration/integralBalance', {custom:{id:21}})
				.then(res => {
					uni.stopPullDownRefresh();
					this.isLoading = false;
					if (res.msg) {
						this.obj = res.msg;
					}
				})
				.catch(e => {
					this.isLoading = false;
				});
		},
		//保存数据
		saveData() {
			this.$refs.uForm
				.validate()
				.then(res => {
					if (this.obj.update_time) {
						//更新
						uni.$u.http
							.put('/madmin/configuration/integralBalance', this.obj,{custom:{id:21}})
							.then(res => {
								this.$refs.uToast.show({
									message: '更新成功',
									type: 'success',
									complete: () => {
										this.getConfig();
									}
								});
							})
							.catch(e => {});
					} else {
						//新增
						uni.$u.http
							.post('/madmin/configuration/integralBalance', this.obj,{custom:{id:21}})
							.then(res => {
								this.$refs.uToast.show({
									message: '新增成功',
									type: 'success',
									complete: () => {
										this.getConfig();
									}
								});
							})
							.catch(e => {});
					}
				})
				.catch(err => {});
		},
		cancal() {
			uni.$u.route({
				type: 'navigateBack',
				delta: 1
			});
		}
	}
};
</script>

<style lang="scss" scoped>
.app {
	background: #fff;
}
.footer {
	position: fixed;
	bottom: 0;
	left: 0;
	width: 100%;
	box-sizing: border-box;
}
</style>
